package mr.ali.webvideo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import mr.ali.webvideo.model.Actor;
import mr.ali.webvideo.model.CollectionActor;
import mr.ali.webvideo.mapper.CollectionActorMapper;
import mr.ali.webvideo.service.IActorService;
import mr.ali.webvideo.service.ICollectionActorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr-ali
 * @since 2025-08-16
 */
@Service
public class CollectionActorServiceImpl extends ServiceImpl<CollectionActorMapper, CollectionActor> implements ICollectionActorService {

    @Resource
    private CollectionActorMapper collectionActorMapper;

    @Resource
    private IActorService actorService;
    /**
     * 根据视频actorid查询相关的的电影信息
     */
    @Override
    public List<CollectionActor> getCollectionActorByUserId(Integer Id) {
        QueryWrapper<CollectionActor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("actor_id", Id);
        return collectionActorMapper.selectList(queryWrapper);
    }

    /**
     * 根据视频videoid查询相关的的演员
     */

    @Override
    public List<CollectionActor> getCollectionActorByVideoId(Integer Id) {
        QueryWrapper<CollectionActor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("video_id", Id);
        List<CollectionActor> tags = collectionActorMapper.selectList(queryWrapper);
        for (CollectionActor video : tags) {
            List<Actor> actor = actorService.getActorByVideoId(video.getActorId());
            video.setActors(actor);
        }
        return tags;
    }

}
